
from .kdad_run import kdad_run
from .spade_run import spade_run
from .patchcore_run import patchcore_run
from .favae_run import favae_run
from .padim_run import padim_run
from .riad_run import riad_run
# from .cutpaste import cutpaste_run
import yaml



def run(args):
    cfg = get_config(args.config)
    weights = args.weights
    phase = args.phase
    if cfg['method'] == 'spade':
        spade_run(cfg,phase,weights)
    elif cfg['method'] == 'patchcore':
        patchcore_run(cfg,phase,weights)
    elif cfg['method'] == 'kdad':
        kdad_run(cfg,phase,weights)
    elif cfg['method'] == 'favae':
        favae_run(cfg,phase,weights)
    elif cfg['method'] == 'riad':
        riad_run(cfg,phase,weights)
    elif cfg['method'] == 'padim':
        padim_run(cfg,phase,weights)
#     elif cfg['method'] == 'cutpaste':
#         cutpaste_run(cfg,phase,weights)
    else:
        raise RuntimeError('Unsupported method!')

def get_config(config):
    with open(config, 'r') as stream:
        return yaml.load(stream)